<template>
	<view class="container">
		<view class="Telephone">
			<view class="text"><text>房屋名字</text></view>
			<view class="input"><input type="" v-model="homeName" placeholder="请输入房屋名字" /></view>
		</view>
		<view class="Telephone">
			<view class="text"><text>地理位置</text></view>
			<view class="input"><input type="" v-model="city" placeholder="请输入房屋所在城市" /></view>
		</view>
		<view class="Submit">
			<button class="button" form-type="submit" @click="submit()" type="primary">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				homeName: '',
				city: '',
			}
		},
		methods: {
			submit() {
				try {
					const homeModule = uni.requireNativePlugin("LJY-HomeModule") //调用android中自定义的插件名称
					uni.showLoading({
					    title: '正在向涂鸦智能平台添加房屋信息'
					});
					//执行涂鸦智能登录
					const ret = homeModule.createHome({ //login表示自定义插件的函数名，第一个表示要传递的参数
						homeName:this.homeName,
						city:this.city
					});
					uni.hideLoading(); //加载结束
					if(ret.code==0){//如果添加成功
						uni.navigateTo({
							url: '/pages/house/Listofhouses'
						});
					}else{//如果失败
						uni.showToast({
						    title: ret.msg,
						    duration: 2000
						});
					}
				} catch (e) { //如果涂鸦智能无法连接
					uni.hideLoading(); //加载结束
					uni.showToast({
					    title: '涂鸦智能家居暂无法使用，请稍后再试',
					    duration: 2000
					});
				}
			}
		}
	}
</script>

<style>
	.Telephone {
		display: flex;
		margin-top: 2%;
		background: #FFFFFF;
		width: 100%;
		height: 100rpx;
		text-align: center;
	}

	.text {
		height: 100rpx;
		width: 30%;
		display: flex;
		justify-content: center;
		line-height: 100rpx;
	}

	.input {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		width: 70%;
		height: 100rpx;
		line-height: 100rpx;
		text-align: left;
	}

	.v-button {
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0;
		padding: 0;
		width: 30%;
		height: 100rpx;
		line-height: 100rpx;
	}

	.submit {
		display: flex;
		margin-top: 5%;
		width: 100%;
		height: 100rpx;
		justify-content: center;
	}

	.button {
		width: 700rpx;
	}
</style>
